<div id="top-panel">
    <div id="panel">
        <ul>
            <li><a href="<?php echo site_url("location"); ?>" class="report_seo">List</a></li>			
        </ul>
    </div>
</div>
<script language="javascript">
	var jq = jQuery.noConflict();
	jq(document).ready(function(){
		jq("#country").change(function(){		
			var a_city 	= jq("a.hidden-city").attr("href");	
			var val		= {'cid' : jq(this).val()};
			jq.post(a_city, val, function(data){
				parse_city_data(data);
			});
		});
		
		jq("#city").change(function(){
			var a_district 	= jq("a.hidden-district").attr("href");
			var val			= {'cid' : jq(this).val()};
			jq.post(a_district, val, function(data){
				parse_district_date(data);
			});
		});
		
		function parse_city_data(data){
			jq("#city option").remove();
			jq("#district_id option").remove();
			var obj = jQuery.parseJSON(data);
			for(var i=0; i<obj.length; i++){
				var str = '<option value="'+obj[i].id+'">'+obj[i].city+'</option>';
				jq("#city").append(str);
			}
		}
		
		function parse_district_date(data){
			jq("#district_id option").remove();
			var obj = jQuery.parseJSON(data);
			for(var i=0; i<obj.length; i++){
				var str = '<option value="'+obj[i].id+'">'+obj[i].name+'</option>';
				jq("#district_id").append(str);
			}
		}
	});
</script>
<div id="wrapper">
	<div id="content">
		<div id="rightnow">
			<h3 class="reallynow">New Item</h3>
			<div>
				<?php echo validation_errors(); ?>
			</div>
			<?php echo form_open('location/save') ?>
			<input type="hidden" name="id" value="<?php echo isset($location['id']) ? $location['id'] : ''; ?>" />
			
			<table width="100%">
				<tr>
					<td>Address</td>
					<td><input type="text" name="address" id="address" class="input" value="<?php echo isset($location['address']) ? $location['address'] : '';  ?>" /></td>
				</tr>	
				<tr>
					<td>Description</td>
					<td><textarea name="description" class="input_textarea"><?php echo isset($location['description']) ? $location['description'] : '';  ?></textarea></td>
				</tr>	
				<tr>
					<td>District</td>
					<td>
						<select name="country" id="country">
							<?php foreach($country as $v): ?>
								<option value="<?php echo $v['iso']; ?>" <?php if(isset($location['iso']) && $location['iso']==$v['iso']):?> selected="selected" <?php endif;?>><?php echo $v['name']; ?></option>
							<?php endforeach; ?>
						</select>
						<select name="city" id="city">
							<?php if(isset($city) && count($city)): ?>
								<?php foreach($city as $v): ?>
								<option value="<?php echo $v['id']; ?>" <?php if(isset($location['ci_id']) && $location['ci_id']==$v['id']):?> selected="selected" <?php endif;?>><?php echo $v['city']; ?></option>
							<?php endforeach; ?>
							<?php endif; ?>
						</select>
						<select name="district_id" id="district_id">
							<?php if(isset($district) && count($district)): ?>
								<?php foreach($district as $v): ?>
								<option value="<?php echo $v['id']; ?>" <?php if(isset($location['d_id']) && $location['d_id']==$v['id']):?> selected="selected" <?php endif;?>><?php echo $v['name']; ?></option>
							<?php endforeach; ?>
							<?php endif; ?>
						</select>						
					</td>
				</tr>				
				<tr>
					<td>&nbsp;</td>
					<td><input type="submit" value="Save" >
						<input type="button" value="Cancel" class="btcancel" /></td>
				<tr>
			</table>
		</div>
	</div>
	<a class="hidden-city" href="<?php echo site_url('location/get_city'); ?>"></a>
	<a class="hidden-district" href="<?php echo site_url('location/get_district'); ?>"></a>
</div>